#include "widget.h"
#include "ui_widget.h"
#include<QPushButton>
#include<QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    //QPushButton* btn=new QPushButton(this);
    //btn->setText("关闭窗口");
    //resize(800,600);
    //connect(btn,&QPushButton::clicked,this,&QWidget::close);
    //四个参数，谁，发出什么信号，谁接受，谁什么函数处理

    //ui->setupUi(this);
    //connect(ui->pushButton,&QPushButton::clicked,this,&Widget::close);
    //connect(this,&Widget::MySignal,this,&Widget::MySlots);
    //qt中绝大部分的信号都是定义好的不需要再自己弄了
    //EmitSignal();

    //this->tch=new Teacher(this);
    //this->stu=new student(this);
    ui->setupUi(this);
    //ui->pushButton->setText("上课了");

    //connect(tch,&Teacher::MySignal,stu,&student::StartStudy);
   // connect(ui->pushButton,&QPushButton::clicked,tch,&Teacher::MySignal);
    //EmitSignal();
    connect(this,&Widget::MySingal,this,&Widget::MySlots);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::EmitSignal(){
    //emit MySignal();
    emit this->MySingal("标题1");
}

/*void Widget::MySlots()
{
    qDebug()<<"我成功发射了一个信号";
}*/

void Widget::MySlots(QString str)
{
    //qDebug()<<str;
    this->setWindowTitle(str);
}





void Widget::on_pushButton_clicked()
{
    //ui->pushButton->setText("恭喜你打开了魔盒");
    //srand(time(0));
    //int x=rand()%300;
    //int y=rand()%300;
    //ui->pushButton->move(x,y);
   // emit close();
    EmitSignal();
}
